<?php
namespace Models;
class News extends Model {
    public function getHot($category_id) {
        $sql = 'select id, title, is_top from news where category_id = ' . $category_id
            . ' order by is_top desc, id desc limit 1';
        $stmt = $this->pdo->query($sql);
        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    }

    public function getNewsByCategoryId($category_id) {
        $sql = 'select id, title, is_top, created_at, image from news where category_id = ' . $category_id
            . ' order by is_top desc, id desc';
        $stmt = $this->pdo->query($sql);
        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    }
    public function getNewsById($id) {
        $sql = 'select * from news where id = ' . $id;
        $stmt = $this->pdo->query($sql);
        return $stmt->fetch(\PDO::FETCH_ASSOC);
    }
}